package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.common.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.interceptor.AuthenticationInterceptor;
import com.atguigu.lease.web.admin.properties.AuthPathProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author yjf
 * @version 1.0
 * @description: springmvc的转换器的注册配置类
 * @date 2024/9/7 14:14
 */
@SpringBootConfiguration //springboot配置类，希望容器一启动就加载进去
@EnableConfigurationProperties(value = AuthPathProperties.class)
public class WebAdminMvcConfig implements WebMvcConfigurer{
    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;

    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    @Autowired
    private AuthPathProperties authPathProperties;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(stringToBaseEnumConverterFactory);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       registry.addInterceptor(authenticationInterceptor)
               .addPathPatterns(authPathProperties.getInclude()) //拦截路径
               .excludePathPatterns(authPathProperties.getExclude());  //排除路径
    }

}
